#ifndef _CHAT_H_
#define _CHAT_H_

#include <string>
#include <list>

class ChatManager;
class Message;
class MessageListener;
class PacketCollector;

class Chat {
public:

    /**
     * Creates a new chat with the specified user and thread ID.
     *
     * @param chatManager the chatManager the chat will use.
     * @param participant the user to chat with.
     * @param threadID the thread ID to use.
     */
    Chat(ChatManager * chatManager, std::string participant, std::string threadID);

    /**
     * Returns the thread id associated with this chat, which corresponds to the
     * <tt>thread</tt> field of XMPP messages. This method may return <tt>null</tt>
     * if there is no thread ID is associated with this Chat.
     *
     * @return the thread ID of this chat.
     */
	const std::string getThreadID() const{
        return threadID;
    }
	
    /**
     * Returns the name of the user the chat is with.
     *
     * @return the name of the user the chat is occuring with.
     */
	const std::string getParticipant() const{
        return participant;
    }
	
    /**
     * Sends the specified text as a message to the other chat participant.
     * This is a convenience method for:
     *
     * <pre>
     *     Message message = chat.createMessage();
     *     message.setBody(messageText);
     *     chat.sendMessage(message);
     * </pre>
     *
     * @param text the text to send.
     */
    void sendMessage(std::string & text) ;

    /**
     * Sends a message to the other chat participant. The thread ID, recipient,
     * and message type of the message will automatically set to those of this chat.
     *
     * @param message the message to send.
     * @throws XMPPException if an error occurs sending the message.
     */
    void sendMessage(Message * message) ;

    /**
     * Adds a packet listener that will be notified of any new messages in the
     * chat.
     *
     * @param listener a packet listener.
     */
    void addMessageListener(MessageListener * listener) ;	

    void removeMessageListener(MessageListener * listener) ;
	
    /**
     * Returns an unmodifiable collection of all of the listeners registered with this chat.
     *
     * @return an unmodifiable collection of all of the listeners registered with this chat.
     */
	std::list<MessageListener*> getListeners();

    /**
     * Creates a {@link org.jivesoftware.smack.PacketCollector} which will accumulate the Messages
     * for this chat. Always cancel PacketCollectors when finished with them as they will accumulate
     * messages indefinitely.
     *
     * @return the PacketCollector which returns Messages for this chat.
     */
    PacketCollector * createCollector() ;
	
    /**
     * Delivers a message directly to this chat, which will add the message
     * to the collector and deliver it to all listeners registered with the
     * Chat. This is used by the XMPPConnection class to deliver messages
     * without a thread ID.
     *
     * @param message the message.
     */
    void deliver(Message * message) ;

	bool operator==( const Chat & ) const;

protected:

private:
	ChatManager* chatManager;
	std::string threadID;
	std::string participant;
	std::list<MessageListener*> listeners ;
};

#endif // -- _CHAT_H_
